﻿#region Using directives

using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using NetROS.Tiers.Entities;
using NetROS.Tiers.Data;

#endregion

namespace NetROS.Tiers.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="VwRadniNalogVezeProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract class VwRadniNalogVezeProviderBaseCore : EntityViewProviderBase<VwRadniNalogVeze>
	{
		#region Custom Methods
		
		
		#region _vwRadniNalogVeze_GetTreeForIDDok
		
		/// <summary>
		///	This method wrap the '_vwRadniNalogVeze_GetTreeForIDDok' stored procedure. 
		/// </summary>
		/// <param name="IDDokument"> A <c>System.Int32?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="VList&lt;VwRadniNalogVeze&gt;"/> instance.</returns>
		public VList<VwRadniNalogVeze> GetTreeForIDDok(System.Int32? @IDDokument)
		{
			return GetTreeForIDDok(null, 0, int.MaxValue , @IDDokument);
		}
		
		/// <summary>
		///	This method wrap the '_vwRadniNalogVeze_GetTreeForIDDok' stored procedure. 
		/// </summary>
		/// <param name="IDDokument"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="VList&lt;VwRadniNalogVeze&gt;"/> instance.</returns>
		public VList<VwRadniNalogVeze> GetTreeForIDDok(int start, int pageLength, System.Int32? @IDDokument)
		{
			return GetTreeForIDDok(null, start, pageLength , @IDDokument);
		}
				
		/// <summary>
		///	This method wrap the '_vwRadniNalogVeze_GetTreeForIDDok' stored procedure. 
		/// </summary>
		/// <param name="IDDokument"> A <c>System.Int32?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <returns>A <see cref="VList&lt;VwRadniNalogVeze&gt;"/> instance.</returns>
		public VList<VwRadniNalogVeze> GetTreeForIDDok(TransactionManager transactionManager, System.Int32? @IDDokument)
		{
			return GetTreeForIDDok(transactionManager, 0, int.MaxValue , @IDDokument);
		}
		
		/// <summary>
		///	This method wrap the '_vwRadniNalogVeze_GetTreeForIDDok' stored procedure. 
		/// </summary>
		/// <param name="IDDokument"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="VList&lt;VwRadniNalogVeze&gt;"/> instance.</returns>
		public abstract VList<VwRadniNalogVeze> GetTreeForIDDok(TransactionManager transactionManager, int start, int pageLength , System.Int32? @IDDokument);
		
		#endregion
		
		#endregion

		#region Helper Functions
		
		/*
		///<summary>
		/// Fill an VList&lt;VwRadniNalogVeze&gt; From a DataSet
		///</summary>
		/// <param name="dataSet">the DataSet</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList&lt;VwRadniNalogVeze&gt;"/></returns>
		protected static VList&lt;VwRadniNalogVeze&gt; Fill(DataSet dataSet, VList<VwRadniNalogVeze> rows, int start, int pagelen)
		{
			if (dataSet.Tables.Count == 1)
			{
				return Fill(dataSet.Tables[0], rows, start, pagelen);
			}
			else
			{
				return new VList<VwRadniNalogVeze>();
			}	
		}
		
		
		///<summary>
		/// Fill an VList&lt;VwRadniNalogVeze&gt; From a DataTable
		///</summary>
		/// <param name="dataTable">the DataTable that hold the data.</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList<VwRadniNalogVeze>"/></returns>
		protected static VList&lt;VwRadniNalogVeze&gt; Fill(DataTable dataTable, VList<VwRadniNalogVeze> rows, int start, int pagelen)
		{
			int recordnum = 0;
			
			System.Collections.IEnumerator dataRows =  dataTable.Rows.GetEnumerator();
			
			while (dataRows.MoveNext() && (pagelen != 0))
			{
				if(recordnum >= start)
				{
					DataRow row = (DataRow)dataRows.Current;
				
					VwRadniNalogVeze c = new VwRadniNalogVeze();
					c.Od = (Convert.IsDBNull(row["Od"]))?string.Empty:(System.String)row["Od"];
					c.TipDokumenta = (Convert.IsDBNull(row["TipDokumenta"]))?string.Empty:(System.String)row["TipDokumenta"];
					c.Oznaka = (Convert.IsDBNull(row["Oznaka"]))?string.Empty:(System.String)row["Oznaka"];
					c.Datum = (Convert.IsDBNull(row["Datum"]))?DateTime.MinValue:(System.DateTime)row["Datum"];
					c.IDChild = (Convert.IsDBNull(row["IDChild"]))?(int)0:(System.Int32)row["IDChild"];
					c.IDParent = (Convert.IsDBNull(row["IDParent"]))?(int)0:(System.Int32)row["IDParent"];
					c.IDDokumentTip = (Convert.IsDBNull(row["IDDokumentTip"]))?(int)0:(System.Int32)row["IDDokumentTip"];
					c.IDGrupe = (Convert.IsDBNull(row["IDGrupe"]))?(int)0:(System.Int32)row["IDGrupe"];
					c.AcceptChanges();
					rows.Add(c);
					pagelen -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		*/	
						
		///<summary>
		/// Fill an <see cref="VList&lt;VwRadniNalogVeze&gt;"/> From a DataReader.
		///</summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pageLength">number of row.</param>
		///<returns>a <see cref="VList&lt;VwRadniNalogVeze&gt;"/></returns>
		protected VList<VwRadniNalogVeze> Fill(IDataReader reader, VList<VwRadniNalogVeze> rows, int start, int pageLength)
		{
			int recordnum = 0;
			while (reader.Read() && (pageLength != 0))
			{
				if(recordnum >= start)
				{
					VwRadniNalogVeze entity = null;
					if (DataRepository.Provider.UseEntityFactory)
					{
						entity = EntityManager.CreateViewEntity<VwRadniNalogVeze>("VwRadniNalogVeze",  DataRepository.Provider.EntityCreationalFactoryType); 
					}
					else
					{
						entity = new VwRadniNalogVeze();
					}
					entity.Od = (System.String)reader["Od"];
					//entity.Od = (Convert.IsDBNull(reader["Od"]))?string.Empty:(System.String)reader["Od"];
					entity.TipDokumenta = (System.String)reader["TipDokumenta"];
					//entity.TipDokumenta = (Convert.IsDBNull(reader["TipDokumenta"]))?string.Empty:(System.String)reader["TipDokumenta"];
					entity.Oznaka = (System.String)reader["Oznaka"];
					//entity.Oznaka = (Convert.IsDBNull(reader["Oznaka"]))?string.Empty:(System.String)reader["Oznaka"];
					entity.Datum = (System.DateTime)reader["Datum"];
					//entity.Datum = (Convert.IsDBNull(reader["Datum"]))?DateTime.MinValue:(System.DateTime)reader["Datum"];
					entity.IDChild = (System.Int32)reader["IDChild"];
					//entity.IDChild = (Convert.IsDBNull(reader["IDChild"]))?(int)0:(System.Int32)reader["IDChild"];
					entity.IDParent = (System.Int32)reader["IDParent"];
					//entity.IDParent = (Convert.IsDBNull(reader["IDParent"]))?(int)0:(System.Int32)reader["IDParent"];
					entity.IDDokumentTip = (System.Int32)reader["IDDokumentTip"];
					//entity.IDDokumentTip = (Convert.IsDBNull(reader["IDDokumentTip"]))?(int)0:(System.Int32)reader["IDDokumentTip"];
					entity.IDGrupe = (System.Int32)reader["IDGrupe"];
					//entity.IDGrupe = (Convert.IsDBNull(reader["IDGrupe"]))?(int)0:(System.Int32)reader["IDGrupe"];
					entity.AcceptChanges();
					rows.Add(entity);
					pageLength -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		
		
		/// <summary>
		/// Refreshes the <see cref="VwRadniNalogVeze"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="VwRadniNalogVeze"/> object to refresh.</param>
		protected void RefreshEntity(IDataReader reader, VwRadniNalogVeze entity)
		{
			reader.Read();
			entity.Od = (System.String)reader["Od"];
			//entity.Od = (Convert.IsDBNull(reader["Od"]))?string.Empty:(System.String)reader["Od"];
			entity.TipDokumenta = (System.String)reader["TipDokumenta"];
			//entity.TipDokumenta = (Convert.IsDBNull(reader["TipDokumenta"]))?string.Empty:(System.String)reader["TipDokumenta"];
			entity.Oznaka = (System.String)reader["Oznaka"];
			//entity.Oznaka = (Convert.IsDBNull(reader["Oznaka"]))?string.Empty:(System.String)reader["Oznaka"];
			entity.Datum = (System.DateTime)reader["Datum"];
			//entity.Datum = (Convert.IsDBNull(reader["Datum"]))?DateTime.MinValue:(System.DateTime)reader["Datum"];
			entity.IDChild = (System.Int32)reader["IDChild"];
			//entity.IDChild = (Convert.IsDBNull(reader["IDChild"]))?(int)0:(System.Int32)reader["IDChild"];
			entity.IDParent = (System.Int32)reader["IDParent"];
			//entity.IDParent = (Convert.IsDBNull(reader["IDParent"]))?(int)0:(System.Int32)reader["IDParent"];
			entity.IDDokumentTip = (System.Int32)reader["IDDokumentTip"];
			//entity.IDDokumentTip = (Convert.IsDBNull(reader["IDDokumentTip"]))?(int)0:(System.Int32)reader["IDDokumentTip"];
			entity.IDGrupe = (System.Int32)reader["IDGrupe"];
			//entity.IDGrupe = (Convert.IsDBNull(reader["IDGrupe"]))?(int)0:(System.Int32)reader["IDGrupe"];
			reader.Close();
	
			entity.AcceptChanges();
		}
		
		/*
		/// <summary>
		/// Refreshes the <see cref="VwRadniNalogVeze"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="VwRadniNalogVeze"/> object.</param>
		protected static void RefreshEntity(DataSet dataSet, VwRadniNalogVeze entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.Od = (Convert.IsDBNull(dataRow["Od"]))?string.Empty:(System.String)dataRow["Od"];
			entity.TipDokumenta = (Convert.IsDBNull(dataRow["TipDokumenta"]))?string.Empty:(System.String)dataRow["TipDokumenta"];
			entity.Oznaka = (Convert.IsDBNull(dataRow["Oznaka"]))?string.Empty:(System.String)dataRow["Oznaka"];
			entity.Datum = (Convert.IsDBNull(dataRow["Datum"]))?DateTime.MinValue:(System.DateTime)dataRow["Datum"];
			entity.IDChild = (Convert.IsDBNull(dataRow["IDChild"]))?(int)0:(System.Int32)dataRow["IDChild"];
			entity.IDParent = (Convert.IsDBNull(dataRow["IDParent"]))?(int)0:(System.Int32)dataRow["IDParent"];
			entity.IDDokumentTip = (Convert.IsDBNull(dataRow["IDDokumentTip"]))?(int)0:(System.Int32)dataRow["IDDokumentTip"];
			entity.IDGrupe = (Convert.IsDBNull(dataRow["IDGrupe"]))?(int)0:(System.Int32)dataRow["IDGrupe"];
			entity.AcceptChanges();
		}
		*/
			
		#endregion Helper Functions
	}//end class

	#region VwRadniNalogVezeFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwRadniNalogVeze"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwRadniNalogVezeFilterBuilder : SqlFilterBuilder<VwRadniNalogVezeColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwRadniNalogVezeFilterBuilder class.
		/// </summary>
		public VwRadniNalogVezeFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwRadniNalogVezeFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwRadniNalogVezeFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwRadniNalogVezeFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwRadniNalogVezeFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwRadniNalogVezeFilterBuilder

	#region VwRadniNalogVezeParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwRadniNalogVeze"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwRadniNalogVezeParameterBuilder : ParameterizedSqlFilterBuilder<VwRadniNalogVezeColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwRadniNalogVezeParameterBuilder class.
		/// </summary>
		public VwRadniNalogVezeParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwRadniNalogVezeParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwRadniNalogVezeParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwRadniNalogVezeParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwRadniNalogVezeParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwRadniNalogVezeParameterBuilder
} // end namespace
